<?php
namespace App\Http\Controllers\Xcx\Mall;

use App\Service\Xcx\Mall\CartService;
use Illuminate\Http\Request;

class CartController extends BaseController
{
    //购物车

    //列表
    public function getList(Request $request)
    {
        $uid = $request->post('uid', 0);
        $pas['start'] = $request->post('page', 1);
        $pas['limit'] = $request->post('size', 6);
        $res = CartService::getList($uid, $pas);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //添加
    public function add(Request $request)
    {
        $pas['uid'] = $request->post('uid', 0);
        $pas['gid'] = $request->post('gid', 0);
        $pas['num'] = $request->post('num', 1);
        $res = CartService::add($pas);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //减少
    public function reduce(Request $request)
    {
        $pas['uid'] = $request->post('uid', 0);
        $pas['gid'] = $request->post('gid', 0);
        $res = CartService::reduce($pas);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }
}